<!--

    Copyright (C) 2015 The Gravitee team (http://gravitee.io)

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

            http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

-->
<div class="gv-page-container">
  <a [routerLink]="['..']" class="gv-back-link"><small><< Back to device identifier plugins</small></a>
  <h1>{{deviceIdentifier.name}}</h1>
  <div fxLayout="row">
    <div fxLayout="column" fxFlex="70">
      <form #deviceIdentifierForm="ngForm">
        <div class="gv-form-section">
          <mat-form-field appearance="outline" floatLabel="always">
            <mat-label>Name</mat-label>
            <input matInput type="text" placeholder="Name" name="name" [(ngModel)]="deviceIdentifier.name" required
                   [readonly]="!editMode">
            <mat-hint>Device identifier name</mat-hint>
          </mat-form-field>
          <mat-form-field appearance="outline" floatLabel="always">
            <input matInput type="text" placeholder="Type" name="type" disabled [value]="displayType(deviceIdentifier.type)" />
            <mat-hint>Device identifier type</mat-hint>
            <mat-icon matSuffix>devices</mat-icon>
          </mat-form-field>
        </div>

        <div class="gv-form-section">
          <div class="gv-form-section-title">
            <h5>Configuration</h5>
            <mat-divider></mat-divider>
          </div>
          <div>
            <device-identifier-form *ngIf="deviceIdentifier" [deviceIdentifierConfiguration]="deviceIdentifierConfiguration"
                                  [deviceIdentifierSchema]="deviceIdentifierSchema"
                                  (configurationCompleted)="enableDeviceIdentifierDetectionUpdate($event)"></device-identifier-form>
          </div>
        </div>

        <div fxLayout="row" *ngIf="editMode">
          <button mat-raised-button
                  [disabled]="(!deviceIdentifierForm.valid || deviceIdentifierForm.pristine) && (!configurationIsValid || configurationPristine) && !formChanged"
                  (click)="update()">SAVE
          </button>
        </div>
      </form>

      <div *hasPermission="['domain_device_identifier_delete']" class="gv-page-delete-zone" fxLayout="column">
        <p>This operation cannot be undone.</p>
        Configuration will be deleted, applications will not be able to use this device identifier plugin anymore.
        <div class="gv-page-delete-button" fxLayout="row">
          <span fxFlex></span>
          <button mat-raised-button color="warn" (click)="delete($event)">DELETE</button>
        </div>
      </div>
    </div>
    <div class="gv-page-description" fxFlex>
      <h3>Device Identifier ?</h3>
      <div class="gv-page-description-content">
        <p>Device Identifier plugin allows you to remember the devices of your users for Multi-factor authentication.</p>
      </div>
    </div>
  </div>
</div>
